/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package dawnland03.model.action.handler;

import dawnland03.model.action.parameter.ActionOutputParam;
import dawnland03.model.action.ActionType;
import dawnland03.model.action.Action;
import org.apache.log4j.Logger;

/**
 * @author Petru Obreja (obrejap@yahoo.com)
 */
public class OutputDisplayHandleStrategy implements HandleStrategy {

    private static Logger logger = Logger.getLogger(OutputDisplayHandleStrategy.class.getName());

    public void handle(Action action) {
        ActionType actionType = action.getActionType();
        StringBuilder stringBuilder = new StringBuilder();
        switch (actionType) {
            case GATHER:
                stringBuilder.append("Gather action ").append("owner id: ").append(action.getOwner().getId()).append(" ");
                stringBuilder.append("item gathered: ").append(action.getOutputParameters().getOutputParameter(ActionOutputParam.ITEM));
                break;
            case INIT:
                stringBuilder.append("Init action ").append("owner: ").append(action.getOwner().getId());
                break;
            case MOVE:
                stringBuilder.append("Move action ").append("owner: ").append(action.getOwner().getId()).append(" ");
                stringBuilder.append("destination: ").append(action.getOutputParameters().getOutputParameter(ActionOutputParam.DESTINATION));
                break;
            case ACQUIRE_LOCK:
                stringBuilder.append("Acquire lock action ").append("owner: ").append(action.getOwner().getId()).append(" ");
                stringBuilder.append("destination: ").append(action.getOutputParameters().getOutputParameter(ActionOutputParam.DESTINATION));
                break;
            case RELEASE_LOCK:
                stringBuilder.append("Release lock action ").append("owner: ").append(action.getOwner().getId()).append(" ");
                stringBuilder.append("destination: ").append(action.getOutputParameters().getOutputParameter(ActionOutputParam.DESTINATION));
                break;
            default:
                System.out.println("Unknown output display action handled for " + action.getOwner());
        }
        boolean completed = (Boolean) action.getOutputParameters().getOutputParameter(ActionOutputParam.COMPLETED);
        if (completed) {
            stringBuilder.append(" was completed.");
        } else {
            stringBuilder.append(" failed.");
        }

        if (logger.isDebugEnabled()) {
            logger.debug(stringBuilder);
        }
    }

}
